import axios from 'axios';
import router from '../router';
import store from '../store'
axios.defaults.baseURL = '/api'
axios.interceptors.request.use((config) => {
    const token=store.state.user.token;
    if(token){
        config.headers.authorization="Bearer" + token
    }
    return {...config}
})
axios.interceptors.response.use((response) => {
    return response.data
},err=>{
    if(err.response){
        switch(err.response.status){
            case 401:
                router.push("/login")
            break;
            case 404:
                alert("接口未找打")
            break;
        }
    }
    return Promise.reject(err)
})

export default axios;